home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / SmallTalk / Association.st < prev    next >
Text File  |  1995-08-25  |  3KB  |  117 lines

  1. "======================================================================
  2. |
  3. |   Association Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbb         16 Mar 91      Class creation now separate statement.
  34. |
  35. | sbyrne     25 Apr 89      created.
  36. |
  37. "
  38.  
  39. LookupKey subclass: #Association
  40.       instanceVariableNames: 'key value'
  41.       classVariableNames: ''
  42.       poolDictionaries: ''
  43.       category: nil
  44. !
  45.  
  46. Association comment: 
  47. 'My instances represent a mapping between two objects.  Typically, my
  48. "key" object is a symbol, but I don''t require this.  My "value" object has 
  49. no conventions associated with it; it can be any object at all.' !
  50.           
  51.  
  52. !Association class methodsFor: 'basic'!
  53.  
  54. key: aKey value: aValue
  55.     ^self new key: aKey value: aValue
  56. !!
  57.  
  58.  
  59.  
  60. !Association methodsFor: 'accessing'!
  61.  
  62. value: aValue
  63.     value _ aValue
  64. !
  65.  
  66. key: aKey value: aValue
  67.     key _ aKey.
  68.     value _ aValue
  69. !
  70.  
  71. key
  72.     ^key
  73. !
  74.  
  75. value
  76.     ^value
  77. !!
  78.  
  79.  
  80.  
  81. !Association methodsFor: 'testing'!
  82.  
  83. = anAssociation
  84.     ^key = anAssociation key and: [ value = anAssociation value ]
  85. !
  86.  
  87. hash
  88.     ^key hash + value hash
  89.  
  90. !!
  91.  
  92.  
  93.  
  94.  
  95. !Association methodsFor: 'printing'!
  96.  
  97. printOn: aStream
  98.     self key printOn: aStream.
  99.     aStream nextPutAll: '->'.
  100.     self value printOn: aStream
  101. !!
  102.  
  103.  
  104.  
  105. !Association methodsFor: 'storing'!
  106.  
  107. storeOn: aStream
  108.     aStream nextPutAll: '(Association key: '.
  109.     self key storeOn: aStream.
  110.     aStream nextPutAll: ' value: '.
  111.     self value storeOn: aStream.
  112.     aStream nextPut: $)
  113. !!
  114.  
  115.